#include <string.h>
#include <stdio.h>

/*
 * 结构体与普通变量之间的相似之处		P164
 */

int main()
{
	char s[16];
	int a;
	float f;
	
	strcpy(&s[0], "Hello, xiaozhi!");
	a = 0x666;
	f = 6.6;

	printf("%s %x %f.\n", &s[0], a, f);
}

/*
	Hello, xiaozhi! 666 6.600000.
 */

#if 0

1.将字符串拆解为整型常量，然后赋值到栈空间上

/*
 * intel
 */
0000000000001169 <main>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	48 83 ec 30          	sub    $0x30,%rsp
    1175:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    117c:	00 00 
    117e:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-0x8=rax
    1182:	31 c0                	xor    %eax,%eax		// eax=0
    1184:	48 8d 45 e0          	lea    -0x20(%rbp),%rax		// rax=rbp-0x20
    1188:	48 be 48 65 6c 6c 6f 	movabs $0x78202c6f6c6c6548,%rsi	// rsi=0x78202c6f6c6c6548="x ,olleH"
    118f:	2c 20 78 
    1192:	48 bf 69 61 6f 7a 68 	movabs $0x2169687a6f6169,%rdi	// rdi=0x2169687a6f6169="!ihzoai"
    1199:	69 21 00 
    119c:	48 89 30             	mov    %rsi,(%rax)		// (rax)=rsi
    119f:	48 89 78 08          	mov    %rdi,0x8(%rax)		// (rax)+8=rdi
    11a3:	c7 45 d8 66 06 00 00 	movl   $0x666,-0x28(%rbp)	// rbp-0x28=0x666
    11aa:	f3 0f 10 05 5e 0e 00 	movss  0xe5e(%rip),%xmm0        # 2010 <_IO_stdin_used+0x10> // xmm0=rip+0xe5e 将一个单精度数传输到xmm寄存器的低32位
    11b1:	00 
    11b2:	f3 0f 11 45 dc       	movss  %xmm0,-0x24(%rbp)	// rbp-0x24=xmm0 将一个单精度数传输到xmm寄存器的低32位
    11b7:	f3 0f 5a 45 dc       	cvtss2sd -0x24(%rbp),%xmm0	// xmm0=rbp-0x24 把源存储器低32位1个单精度浮点数变成1个双精度浮点数,结果送入目的寄存器的低64位,高64位不变.
    11bc:	8b 55 d8             	mov    -0x28(%rbp),%edx		// edx=rbp-0x28
    11bf:	48 8d 45 e0          	lea    -0x20(%rbp),%rax		// rax=rbp-0x20
    11c3:	48 89 c6             	mov    %rax,%rsi		// rsi=rax
    11c6:	48 8d 3d 37 0e 00 00 	lea    0xe37(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> // rdi=rip+0xe37
    11cd:	b8 01 00 00 00       	mov    $0x1,%eax		// eax=0x1
    11d2:	e8 99 fe ff ff       	callq  1070 <printf@plt>	// printf()
    11d7:	b8 00 00 00 00       	mov    $0x0,%eax		// eax=0
    11dc:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx		// rcx=rbp-0x8
    11e0:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx		// rcx=fs:0x28
    11e7:	00 00 
    11e9:	74 05                	je     11f0 <main+0x87>
    11eb:	e8 70 fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    11f0:	c9                   	leaveq 
    11f1:	c3                   	retq   
    11f2:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    11f9:	00 00 00 
    11fc:	0f 1f 40 00          	nopl   0x0(%rax)

/*
 * arm
 */
000000000040055c <main>:
  40055c:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  400560:	910003fd 	mov	x29, sp				// x29=fp=sp
  400564:	910063a2 	add	x2, x29, #0x18			// x2=x29+0x18
  400568:	90000000 	adrp	x0, 400000 <_init-0x3e8>	// x0=400000
  40056c:	9119a000 	add	x0, x0, #0x668			// x0=400668
  400570:	a9400400 	ldp	x0, x1, [x0]			// x0=[x0], x1=[x0+8]
  400574:	a9000440 	stp	x0, x1, [x2]			// [x2]=x0, [x2+8]=x1 
  400578:	5280ccc0 	mov	w0, #0x666                 	// #1638 w0=0x666
  40057c:	b9002fa0 	str	w0, [x29, #44]			// x29+44=w0
  400580:	52866660 	mov	w0, #0x3333                	// #13107	w0=0x3333
  400584:	72a81a60 	movk	w0, #0x40d3, lsl #16		// w0=0x40d3<<16
  400588:	1e270000 	fmov	s0, w0				// s0=w0
  40058c:	bd002ba0 	str	s0, [x29, #40]			// x29+40=s0
  400590:	bd402ba0 	ldr	s0, [x29, #40]			// s0=x29+40
  400594:	1e22c000 	fcvt	d0, s0				// d0=s0
  400598:	910063a1 	add	x1, x29, #0x18			// x1=x29+0x18
  40059c:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005a0:	9119e000 	add	x0, x0, #0x678
  4005a4:	b9402fa2 	ldr	w2, [x29, #44]			// w2=x29+44
  4005a8:	97ffffaa 	bl	400450 <printf@plt>		// printf()
  4005ac:	52800000 	mov	w0, #0x0                   	// #0
  4005b0:	a8c37bfd 	ldp	x29, x30, [sp], #48
  4005b4:	d65f03c0 	ret


 #endif
